﻿using System;
using System.Collections.Generic;
 
using System.Text;
using System.Data;
using Microsoft.Win32;

namespace Demo
{
    class databinding
    {
        static string GetDBPath()
        {
            string dbPath;
            RegistryKey regKey = Registry.ClassesRoot.OpenSubKey("FarPoint.Win.Spread\\Common");
            if (regKey != null)
                dbPath = (string)regKey.GetValue("v52005");
            else
                dbPath = "\\Program Files\\GrapeCity\\Spread.WinForms.5.dotNet20\\Common\\";
            dbPath += "Nwind.mdb";
            return dbPath;
        }

        static public DataSet GetNWINDData(string dt)
        {
            string sqlStr = "SELECT * FROM " + dt;
            return GetNWINDDataComplete(sqlStr);
        }

        static public DataSet GetNWINDDataComplete(string sqlStr)
        {
            string conStr = "Provider=Microsoft.JET.OLEDB.4.0;data source=" + GetDBPath();
            System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(conStr);
            DataSet ds = new DataSet();
            System.Data.OleDb.OleDbDataAdapter da = new System.Data.OleDb.OleDbDataAdapter(sqlStr, conn);
            da.Fill(ds);
            return ds;
        }
    }
}
